-- Pr8
module Main (
    main
) where

import Data.List (delete)

type Arc = (Int, Int)
type Graph = [Arc]

-- params: least of graph, current vertex, end vertex, current path
-- returns: list of paths from start vertex to end vertex
allPaths :: Graph -> Int -> Int -> [Arc] -> [[Arc]]
allPaths [] current end path
    | current == end = [path]
    | otherwise = []
allPaths subgraph current end path
    | current == end = [path]
    | otherwise = let
    neighbourArcs = filter (\(v1, v2) -> v1 == current) subgraph
    in foldl (\acc arc@(x, y) -> let
        paths = allPaths (delete arc subgraph) y end (path ++ [arc])
        in if null paths then acc else (acc ++ paths)) [] neighbourArcs


main = do
    let g = [(1,2), (1,3), (3, 2), (2, 4), (2, 3)] :: Graph
    print $ allPaths g 1 4 []
